package fire.room;

import java.util.ArrayList;
import util.OOMLoad;

import jgame.JGColor;
import jgame.JGObject;
import jgame.JGPoint;
import jgame.impl.EngineLogic;

import fire.Main;
import fire.chacracter.Player;
import fire.gui.Dialog;
import fire.gui.LoadingScreen;

public class Map {
	protected String tbl, oomFile;
	protected int hTiles, vTiles;
	protected ArrayList<JGObject> oomList;
	private boolean isLoaded;
	private Player player;
	private String name;
	private int playerY;
	private int playerX;

	public Map(String tbl, String oomFile, int hTiles, int vTiles, int playerX,
			int playerY) {
		this.tbl = tbl;
		this.oomFile = oomFile;
		this.hTiles = hTiles;
		this.vTiles = vTiles;
		this.oomList = new ArrayList<JGObject>();
		this.player = Player.getPlayer();
		this.playerX = playerX;
		this.playerY = playerY;
		this.name = oomFile.substring(oomFile.lastIndexOf("/") + 1,
				oomFile.indexOf("."));
		this.isLoaded = false;
	}

	public void createMap(Main main) {
		LoadingScreen l = new LoadingScreen("loadding", 70,
				Main.VIEW_FOLLOW_PLAYER);
		main.setView(Main.VIEW_LOADING);
		if (!isLoaded) {
			if (tbl != null) {
				main.defineMedia(tbl);
			}
			OOMLoad.oomLoad(oomFile, oomList, main);
			isLoaded = true;
		} else {
			active();
		}
		player.setPos(playerX, playerY);
		main.setBGImage(name);
		main.setPFSize(hTiles, vTiles);
		// main.setView(Main.VIEW_FOLLOW_PLAYER);
	}

	public void suspend() {
		for (JGObject obj : oomList) {
			obj.setResumeMode(false);
			obj.suspend();
		}
	}

	public void active() {
		for (JGObject obj : oomList) {
			obj.setResumeMode(true);
		}
	}

	public String getName() {
		return name;
	}

	public Player getPlayer() {
		return player;
	}
}